package com.snpic.appaw.module.third.api.aliyun;

import com.aliyun.dypnsapi20170525.models.GetAuthTokenResponseBody;
import com.snpic.appaw.framework.common.pojo.CommonResult;
import com.snpic.appaw.module.third.api.aliyun.dto.GetAuthTokenRequestDTO;
import com.snpic.appaw.module.third.api.aliyun.dto.GetAuthTokenResponseDTO;
import com.snpic.appaw.module.third.service.aliyun.PhoneNumberAuthenticationService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import static com.snpic.appaw.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.snpic.appaw.module.third.enums.ErrorCodeConstants.ALIYUN_INTERFACE01_ERROR;

/**
 * @author JiJun
 * @date 2025/9/21 15:48
 * @修改时间 2025/9/21 15:48
 * @description 阿里云号码认证API实现类
 */
@RestController // 提供 RESTful API 接口，给 Feign 调用
@Validated
public class PhoneNumberAuthenticationApiImpl implements PhoneNumberAuthenticationApi {

	@Resource
	private PhoneNumberAuthenticationService phoneNumberAuthenticationService;


	@Override
	public CommonResult<GetAuthTokenResponseBody> getAuthToken(GetAuthTokenRequestDTO reqDTO) {
		GetAuthTokenResponseBody authToken = null;
		try {
			authToken = phoneNumberAuthenticationService.getAuthToken(reqDTO);
		} catch (Exception e) {
			throw exception(ALIYUN_INTERFACE01_ERROR);
		}
		return CommonResult.success(authToken);
	}
}
